package edu.langnan.xiaoli.service.impl;

import edu.langnan.xiaoli.constant.XiaoLiConstants;
import edu.langnan.xiaoli.core.dto.TestPlaceDTO;
import edu.langnan.xiaoli.mapper.TestPlaceMapper;
import edu.langnan.xiaoli.service.CollegeService;
import edu.langnan.xiaoli.service.TestPlaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @author cql
 */
@Service
public class TestPlaceServiceImpl implements TestPlaceService {

    @Autowired
    private TestPlaceMapper testPlaceMapper;

    @Autowired
    private CollegeService collegeService;

    @Override
    public List<TestPlaceDTO> findTestPlaceListByNid(Integer nid) {

        List<TestPlaceDTO> testPlaces = testPlaceMapper.findTestPlaceListByNid(nid);

        // 学院信息
        for (TestPlaceDTO t : testPlaces) {
            String[] ids = t.getCollegeStr().split(XiaoLiConstants.SEPARATOR);
            Set<String> names = collegeService.findCollegeTestPlace(ids);
            t.setColleges(names);
        }
        return testPlaces;
    }
}
